package com.eastshop.category.adminaction;

import java.util.List;

import com.eastshop.category.service.CategorySerive;
import com.eastshop.category.vo.Category;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/**
 * 后台商品分类管理的Action类
 * @author admin
 *
 */
public class AdminCategoryAction extends ActionSupport implements ModelDriven<Category>{
	// 模型驱动使用的类
	private Category category = new Category();

	public Category getModel() {
		return category;
	}
	
	// 注入商品分类的Service
	private CategorySerive categorySerive;

	public void setCategorySerive(CategorySerive categorySerive) {
		this.categorySerive = categorySerive;
	}
	
	// 查询所有的商品分类
	public String find(){
		List cList = categorySerive.find();
		ActionContext.getContext().getValueStack().set("cList", cList);
		return "find";
	}
	
	// 删除商品分类
	public String delete(){
		// 根据id查询商品的分类
		category = categorySerive.findByCid(category.getCid());
		// 删除商品的分类
		categorySerive.delete(category);
		return "delete";
	}
	
	// 跳转到添加商品分类的页面
	public String add(){
		return "add";
	}
	
	// 添加商品分类
	public String addSubmit(){
		categorySerive.save(category);
		return "addSubmit";
	}
	
	// 跳转到商品分类的修改页面
	public String edit(){
		category = categorySerive.findByCid(category.getCid());
		return "edit";
	}
	
	// 修改商品分类的方法
	public String editSubmit(){
		categorySerive.update(category);
		return "editSubmit";
	}
}
